<template>
  <div class="wrap">
    <div class="sidebar">
      <ul>
        <li v-for="selects in clothes" :key="selects.id" :class="{active:selects.isShow}" v-on:click="cli(selects.classifyId)" class='clickselet'>
          {{selects.classifyName}}
        </li>
      </ul>
    </div>
    <div class="main">
      <router-link
        tag="div"
        :to="{name: 'mall'}"
        v-for="selects2 in clothes2"
        :key="selects2.classifyId"
        class="pro"
      >
        <!-- @click="getId({firstId, lastId: selects2.classifyId})" -->
        <img :src="'https://cdn.bestseller.com.cn' + selects2.miniprogramUrl" alt="">
        <div class="proname">{{selects2.classifyName}}</div>
      </router-link>
    </div>
    <router-view></router-view>
  </div>
</template>

<script>
import Vue from 'vue'
import { Navbar, TabItem } from 'mint-ui'

Vue.component(Navbar.name, Navbar)
Vue.component(TabItem.name, TabItem)
export default {
  name: 'Mall',
  data () {
    return {
      clothes: null,
      clothes2: null,
      firstId: 114762
    }
  },
  methods: {
    cli (id) {
      let len = this.clothes.length
      for (let i = 0; i < len; i++) {
        this.clothes[i].isShow = false
      }
      for (let i = 0; i < len; i++) {
        if (this.clothes[i].classifyId === id) {
          this.clothes[i].isShow = true
          this.cli2(i)
          this.firstId = id
        }
      }
    },
    cli2 (id2) {
      this.clothes2 = this.clothes[id2].list
    }
  },
  created () {
    this.$http.get('https://m.only.cn/classify/h5/ONLY/h5_list.json')
      .then(resp => {
        this.clothes = resp.data.data
        this.clothes2 = resp.data.data[0].list
        let len = this.clothes.length
        for (let i = 0; i < len; i++) {
          this.clothes[i].isShow = false
        }
        this.clothes[0].isShow = 'ture'
      })
  }
}
</script>

<style lang='scss' scoped>
.wrap{
  display: flex;
  width: 100%;
  height: 100%;
  .main{
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    .pro{
      width: 47%;
      display: flex;
      flex-direction: column;
      text-align: center;
      margin-bottom: 20px;
      img{
        width: 100%;
      }
    }
  }
  .sidebar{
    background-color: #dedede;
    width: 100px;
    height: 100%;
    overflow-x: hidden;
    ul{
      li{
        height:50px;
        margin: 10px 0;
        line-height: 50px;
        text-align: center;
        font-size: 14px;
      }
      .active{
        height:50px;
        margin: 10px 0;
        line-height: 50px;
        text-align: center;
        background-color: #fff;
      }
    }
  }
  .main{
    flex: 1;
  }
}
</style>
